package com.fruit.controller.app.lightpay;


import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fruit.controller.base.BaseController;
import com.fruit.pojo.lightpay.LightPayCashier;
import com.fruit.service.lightpay.LightPayManager;
import com.fruit.util.CommonUtil;
import com.fruit.util.ResultInfo;



@Controller
@RequestMapping(value = "/app/lightpay/")
public class LightPayAppController extends BaseController {

	
	@Autowired
	private LightPayManager lightPayService;

	
	@RequestMapping(value = "weChatPay", method = { RequestMethod.POST,RequestMethod.GET })
	@ResponseBody
	public Map<String, Object> wechatPay(@RequestBody LightPayCashier lpc,HttpServletResponse response, HttpServletRequest request){
		this.logBefore(logger, "APP微信支付");
		String tradeId = CommonUtil.getUUID();
		Map<String, Object> resMap = new HashMap<String, Object>();
		try{
			lpc.setIp(CommonUtil.getIpAddr(request));
			resMap = lightPayService.saveWechatPayCashier(tradeId, lpc);
		}catch(Exception e){
			e.printStackTrace();
			resMap.put("result", this.initResult(ResultInfo.ERROR, "系统繁忙", null));
		}

		return resMap;
		
	}
	
	
	
}
